package zozopo.operations.business;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import zozopo.comm.CNSpell;
import zozopo.comm.HTMLDisplay;

import zozopo.database.BusiDatabaseManager;
import zozopo.database.SqlMachine;
import zozopo.manual.operations.ReleaseTB;
import zozopo.operations.comm.DictionaryOS;
import zozopo.operations.comm.OperatingService;



public class StoreOS extends OperatingService{
	
	

	public StoreOS(Connection conn){
		super(conn);
	}
	
	public StoreOS(){
		this.databaseConnection = new BusiDatabaseManager();
		this.conn = databaseConnection.getConnection();
	}
	
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public boolean insertStore(StoreTB store){
		
		SqlMachine sqlMachine = new SqlMachine(conn);
		HashMap<String, Object> insertMap = new HashMap<String, Object>();
		
		insertMap.put(StoreTB.CNBRAND_STORE, store.getCnbrand_store());
		insertMap.put(StoreTB.CNSPELL_STORE, CNSpell.CNToSpell(store.getCnbrand_store()));//把中文品牌转为拼音
		insertMap.put(StoreTB.CONTENT_STORE, store.getContent_store());
		insertMap.put(StoreTB.USERMAIL_STORE, store.getUsermail_store());
		
		insertMap.put(StoreTB.ENBRAND_STORE, store.getEnbrand_store());
		//insertMap.put(StoreTB.FLOW_STORE, store.getCnspell_store());
		insertMap.put(StoreTB.IMAGE_STORE, store.getImage_store());
		//insertMap.put(StoreTB.KIND_STORE, store.getKind_store());
		insertMap.put(StoreTB.LABLE_STORE, store.getLable_store());
		insertMap.put(StoreTB.NAME_STORE, store.getName_store());
		insertMap.put(StoreTB.SHORTNAME_STORE, store.getShortname_store());
		
		insertMap.put(StoreTB.STAR_STORE, store.getStar_store());
		/*insertMap.put(StoreTB.STAR1_STORE, store.getStar1_store());
		insertMap.put(StoreTB.STAR2_STORE, store.getStar2_store());
		insertMap.put(StoreTB.STAR3_STORE, store.getStar3_store());
		insertMap.put(StoreTB.STAR4_STORE, store.getStar4_store());
		insertMap.put(StoreTB.STAR5_STORE, store.getStar5_store());
		insertMap.put(StoreTB.STAR6_STORE, store.getStar6_store());
		insertMap.put(StoreTB.STAR7_STORE, store.getStar7_store());
		insertMap.put(StoreTB.STAR8_STORE, store.getStar8_store());
		insertMap.put(StoreTB.STAR9_STORE, store.getStar9_store());
		insertMap.put(StoreTB.STAR10_STORE, store.getStar10_store());*/
		
		insertMap.put(StoreTB.URL_STORE, store.getUrl_store());
		
		
		return sqlMachine.insertRow(StoreTB.TABLE_NAME, insertMap);
	
	}
	
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 
	 */
	public List<String> selectCnbrandList(int beginPageNum,int pageSize){
		
	
		String sql = "select distinct("+StoreTB.CNBRAND_STORE+") from "+StoreTB.TABLE_NAME+" limit "+beginPageNum+","+pageSize; 
		
		//select distinct(release_brand) from release_subject order by release_views desc
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		List<String> releaseList = null;
		System.out.println(sql);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<String>();
					while(resultSet.next()){
						String brand =resultSet.getString(StoreTB.CNBRAND_STORE);
						releaseList.add(brand);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
		
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 
	 */
	public List<String> selectEnbrandList(int beginPageNum,int pageSize){
		
	
		String sql = "select distinct("+StoreTB.ENBRAND_STORE+") from "+StoreTB.TABLE_NAME+" limit "+beginPageNum+","+pageSize; 
		
		//select distinct(release_brand) from release_subject order by release_views desc
		if(logger.isDebugEnabled()){
			logger.debug("getUserInfoByName() sql:"+sql.toString());
		}
		List<String> releaseList = null;
		System.out.println(sql);
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					releaseList = new ArrayList<String>();
					while(resultSet.next()){
						String brand =resultSet.getString(StoreTB.ENBRAND_STORE);
						releaseList.add(brand);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return releaseList;
		
	}
	/**
	 * @version 1.0
	 * @param ReleaseTB release
	 * @author Shea
	 * @return boolean  
	 * @throws IOException 
	 * @see insertRelease(ImageTB image)
	 */
	public boolean upadteStore(StoreTB store){
		SqlMachine sqlMachine = new SqlMachine(conn);
		HashMap<String, Object> updateMap = new HashMap<String, Object>();
		
		updateMap.put(StoreTB.BRAND_STORE, store.getBrand_store());
		updateMap.put(StoreTB.CNBRAND_STORE, store.getCnbrand_store());
		updateMap.put(StoreTB.CNSPELL_STORE, CNSpell.CNToSpell(store.getCnbrand_store()));
		updateMap.put(StoreTB.ENBRAND_STORE, store.getEnbrand_store());
		updateMap.put(StoreTB.CONTENT_STORE, store.getContent_store());
		updateMap.put(StoreTB.IMAGE_STORE, store.getImage_store());
		
		updateMap.put(StoreTB.LABLE_STORE, store.getLable_store());
		
		updateMap.put(StoreTB.NAME_STORE, store.getName_store());
		updateMap.put(StoreTB.SHORTNAME_STORE, store.getShortname_store());
		updateMap.put(StoreTB.STAR_STORE, store.getStar_store());
		updateMap.put(StoreTB.URL_STORE, store.getUrl_store());
		
		return sqlMachine.updateRow(StoreTB.TABLE_NAME, updateMap, StoreTB.ID_STORE, store.getId_store());
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectStoreBySql(String sql){
		List<StoreTB> storeList = null;
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		DictionaryOS dictionaryOS= new DictionaryOS(conn);
		if(resultSet != null){
				try {
					storeList = new ArrayList<StoreTB>();
					while(resultSet.next()){
						StoreTB store = new StoreTB();
						
						store.setBrand_store(resultSet.getString(StoreTB.BRAND_STORE));
						store.setCnbrand_store(resultSet.getString(StoreTB.CNBRAND_STORE));
						store.setCnspell_store(resultSet.getString(StoreTB.CNSPELL_STORE));
						
						store.setContent_store(resultSet.getString(StoreTB.CONTENT_STORE));
						store.setEnbrand_store(resultSet.getString(StoreTB.ENBRAND_STORE));
						
						store.setFlow_store(resultSet.getInt(StoreTB.FLOW_STORE));
						store.setId_store(resultSet.getInt(StoreTB.ID_STORE));
						
						
						//store.setImage_store(image_store)
						store.setImage_store(resultSet.getString(StoreTB.IMAGE_STORE));
						store.setKind_store(resultSet.getString(StoreTB.KIND_STORE));
						store.setLable_store(resultSet.getString(StoreTB.LABLE_STORE));
						store.setName_store(resultSet.getString(StoreTB.NAME_STORE));
						store.setShortname_store(resultSet.getString(StoreTB.SHORTNAME_STORE));
						 
						store.setStar_store(resultSet.getInt(StoreTB.STAR_STORE));
						
						store.setStar1_store(resultSet.getInt(StoreTB.STAR1_STORE));
						store.setStar2_store(resultSet.getInt(StoreTB.STAR2_STORE));
						store.setStar3_store(resultSet.getInt(StoreTB.STAR3_STORE));
						store.setStar4_store(resultSet.getInt(StoreTB.STAR4_STORE));
						store.setStar5_store(resultSet.getInt(StoreTB.STAR5_STORE));
						store.setStar6_store(resultSet.getInt(StoreTB.STAR6_STORE));
						store.setStar7_store(resultSet.getInt(StoreTB.STAR7_STORE));
						store.setStar8_store(resultSet.getInt(StoreTB.STAR8_STORE));
						store.setStar9_store(resultSet.getInt(StoreTB.STAR9_STORE));
						store.setStar10_store(resultSet.getInt(StoreTB.STAR10_STORE));
						
						store.setStatus_store(resultSet.getString(StoreTB.STATUS_STORE));
						store.setUrl_store(resultSet.getString(StoreTB.URL_STORE));
						
						
						store.setLablevalue(dictionaryOS.getDictValue(store.getLable_store()));//为了显示
						//store.setKindvalue(dictionaryOS.getDictValue(store.getKind_store()));//为了显示
						store.setStarvalue(HTMLDisplay.getStarChar(store.getStar_store()));//为了显示
						
						
						try {
							store.setEncodeCNbrand(java.net.URLEncoder.encode(store.getCnbrand_store(),"utf-8").replaceAll("%", "%25"));
						} catch (UnsupportedEncodingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
						storeList.add(store);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return storeList;
	
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectBySql(String sql){
		List<StoreTB> storeList = null;
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		
		if(resultSet != null){
				try {
					storeList = new ArrayList<StoreTB>();
					while(resultSet.next()){
						StoreTB store = new StoreTB();
						
						store.setBrand_store(resultSet.getString(StoreTB.BRAND_STORE));
						store.setCnbrand_store(resultSet.getString(StoreTB.CNBRAND_STORE));
						store.setCnspell_store(resultSet.getString(StoreTB.CNSPELL_STORE));
						
						store.setContent_store(resultSet.getString(StoreTB.CONTENT_STORE));
						store.setEnbrand_store(resultSet.getString(StoreTB.ENBRAND_STORE));
						
						store.setFlow_store(resultSet.getInt(StoreTB.FLOW_STORE));
						store.setId_store(resultSet.getInt(StoreTB.ID_STORE));
						
						
						//store.setImage_store(image_store)
						store.setImage_store(resultSet.getString(StoreTB.IMAGE_STORE));
						store.setKind_store(resultSet.getString(StoreTB.KIND_STORE));
						store.setLable_store(resultSet.getString(StoreTB.LABLE_STORE));
						store.setName_store(resultSet.getString(StoreTB.NAME_STORE));
						store.setShortname_store(resultSet.getString(StoreTB.SHORTNAME_STORE));
						 
						store.setStar_store(resultSet.getInt(StoreTB.STAR_STORE));
						
						store.setStar1_store(resultSet.getInt(StoreTB.STAR1_STORE));
						store.setStar2_store(resultSet.getInt(StoreTB.STAR2_STORE));
						store.setStar3_store(resultSet.getInt(StoreTB.STAR3_STORE));
						store.setStar4_store(resultSet.getInt(StoreTB.STAR4_STORE));
						store.setStar5_store(resultSet.getInt(StoreTB.STAR5_STORE));
						store.setStar6_store(resultSet.getInt(StoreTB.STAR6_STORE));
						store.setStar7_store(resultSet.getInt(StoreTB.STAR7_STORE));
						store.setStar8_store(resultSet.getInt(StoreTB.STAR8_STORE));
						store.setStar9_store(resultSet.getInt(StoreTB.STAR9_STORE));
						store.setStar10_store(resultSet.getInt(StoreTB.STAR10_STORE));
						
						store.setStatus_store(resultSet.getString(StoreTB.STATUS_STORE));
						store.setUrl_store(resultSet.getString(StoreTB.URL_STORE));
						
			
						storeList.add(store);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return storeList;
	
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectStoreByBrand(String brand){
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME + " WHERE " + 
		StoreTB.CNBRAND_STORE +"='"+brand+"'" +" OR " + StoreTB.ENBRAND_STORE +"='"+brand+"'";
		
		return selectStoreBySql(sql);
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectStoreByBrand(String brand,int pageSize){
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME + " WHERE " + 
		StoreTB.CNBRAND_STORE +"='"+brand+"'" +" OR " + StoreTB.ENBRAND_STORE +"='"+brand+"'"
		+" limit "+0+","+pageSize;
		
		return selectStoreBySql(sql);
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectStoreByBrandOrderByStar(String brand,int pageSize){
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME + " WHERE " + 
		StoreTB.CNBRAND_STORE +"='"+brand+"'" +" OR " + StoreTB.ENBRAND_STORE +"='"+brand+"'"
		+"ORDER BY "+StoreTB.STAR_STORE+" DESC limit "+0+","+pageSize;
		return selectStoreBySql(sql);
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectAllStore(){
		
		List<StoreTB> storeList = null;
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME;
		storeList = selectStoreBySql(sql);
		
		return storeList;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public int getRowNum(){
		
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + StoreTB.TABLE_NAME ;
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public int getRowNum(String brand){
		
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + StoreTB.TABLE_NAME +" where " + StoreTB.CNBRAND_STORE + "='"+brand+"' or" 
		+ StoreTB.ENBRAND_STORE + "='"+brand+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public StoreTB getStoreById(Integer id){
		 
		StoreTB store = new StoreTB();
		
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME + " where " + StoreTB.ID_STORE + " = " + id;

		List<StoreTB> storeList = selectStoreBySql(sql);
		
		for(StoreTB forstore:storeList){
			store = forstore;
		}
		
		return store;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectStoreTB(int beginPageNum,int pageSize){
		
		List<StoreTB> storeList = null;
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME  +" limit "+beginPageNum+","+pageSize; 
		storeList = selectStoreBySql(sql);
		
		return storeList;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<StoreTB> selectStore(String brand,int beginPageNum,int pageSize){
		List<StoreTB> storeList = null;
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME  +" where " + StoreTB.ENBRAND_STORE + "='" + brand + "' or " + StoreTB.CNBRAND_STORE
		+ "='" + brand +"' "
		+ " limit "+beginPageNum+","+pageSize; 
		storeList = selectStoreBySql(sql);
		
		return storeList;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public boolean isExistUrl(String url){
		
		boolean eResult = false;
		
		String sql = "select * from "+StoreTB.TABLE_NAME+" where "+StoreTB.URL_STORE+"='"+url+"'";
		
		//System.out.println(sql);
		
		if(logger.isDebugEnabled()){
			logger.debug("isExist() sql:"+sql.toString());
		}
		
		try {
			ResultSet result = databaseConnection.executeQuery(conn,sql);
		
			if(result.next()){
				eResult = true;
			}
			result.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return eResult;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public boolean isExistUrlAndBrand(String url,String cnbrand,String enbrand){
		
		boolean eResult = false;
		String sql;
		
		if(enbrand.trim().equals("")){
			sql = "select * from "+StoreTB.TABLE_NAME+" where "+StoreTB.URL_STORE+"='"+url+"'" + " and " + 
			StoreTB.CNBRAND_STORE + "='"+cnbrand+"'";
		}//*/
		else if(cnbrand.trim().equals("")){
			sql = "select * from "+StoreTB.TABLE_NAME+" where "+StoreTB.URL_STORE+"='"+url+"'" + " and " + 
			StoreTB.ENBRAND_STORE + "='"+enbrand+"'";
		}//*/
		else{
			sql = "select * from "+StoreTB.TABLE_NAME+" where "+StoreTB.URL_STORE+"='"+url+"'" + " and (" + 
			StoreTB.CNBRAND_STORE + "='"+cnbrand+"' or " + StoreTB.ENBRAND_STORE + "='"+enbrand+"')";
		}
		
		
		//System.out.println(sql);
		
		if(logger.isDebugEnabled()){
			logger.debug("isExist() sql:"+sql.toString());
		}
		
		try {
			ResultSet result = databaseConnection.executeQuery(conn,sql);
		
			if(result.next()){
				eResult = true;
			}
			result.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return eResult;
	}
	
	
	public boolean deleteStoreById(int id){
		SqlMachine sqlMachine = new SqlMachine(conn);
		return sqlMachine.deleteRow(StoreTB.TABLE_NAME, StoreTB.ID_STORE, id);
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 按首字母查询
	 */
	public Map<String,Integer> selectEnbrandMapByFirstCharacter(String firstChar){
		Map<String,Integer> storeMap = null;
		//String sql = "SELECT DISTINCT("+StoreTB.ENBRAND_STORE+") FROM "+StoreTB.TABLE_NAME+" WHERE UPPER(SUBSTRING("+StoreTB.ENBRAND_STORE+" , 1 , 1)) = '"+firstChar+"'";
		
		String sql = "SELECT COUNT("+StoreTB.ENBRAND_STORE+")as rowNum,MAX("+StoreTB.ENBRAND_STORE+") as "+StoreTB.ENBRAND_STORE+" FROM "+StoreTB.TABLE_NAME+" WHERE UPPER(SUBSTRING("+StoreTB.ENBRAND_STORE+" , 1 , 1)) = '"+firstChar+"'"+" GROUP BY "+StoreTB.ENBRAND_STORE+" HAVING COUNT("+StoreTB.ENBRAND_STORE+")";
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					storeMap = new LinkedHashMap<String,Integer>();
					while(resultSet.next()){
						//StoreTB store = new StoreTB();
						//release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						//store.setEnbrand_store(resultSet.getString(StoreTB.ENBRAND_STORE));
						storeMap.put(resultSet.getString(StoreTB.ENBRAND_STORE), resultSet.getInt("rowNum"));
						//storeList.add(store);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return storeMap;
	}
	
	/**
	 * @version 1.0
	 * @param String brand
	 * @author Shea
	 * @return ResultSet  
	 * @throws IOException 
	 * @see 按首拼音字母查询
	 */
	public Map<String,Integer> selectCnbrandMapByFirstCharacter(String firstChar){
		Map<String,Integer> storeMap = null;
		String sql = "SELECT COUNT("+StoreTB.CNBRAND_STORE+")as rowNum,MAX("+StoreTB.CNBRAND_STORE+") as "+StoreTB.CNBRAND_STORE+" FROM "+StoreTB.TABLE_NAME+" WHERE UPPER(SUBSTRING("+StoreTB.CNSPELL_STORE+" , 1 , 1)) = '"+firstChar+"'"+" GROUP BY "+StoreTB.CNBRAND_STORE+" HAVING COUNT("+StoreTB.CNBRAND_STORE+")";
		//String sql = "SELECT DISTINCT("+StoreTB.CNBRAND_STORE+") FROM "+StoreTB.TABLE_NAME+" WHERE UPPER(SUBSTRING("+StoreTB.CNSPELL_STORE+" , 1 , 1)) = '"+firstChar+"'";
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					storeMap = new LinkedHashMap<String,Integer>();
					while(resultSet.next()){
						//StoreTB store = new StoreTB();
						//release.setRelease_id(resultSet.getString(ReleaseTB.RELEASE_ID));
						//store.setEnbrand_store(resultSet.getString(StoreTB.ENBRAND_STORE));
						//store.setCnbrand_store();
						//store.setEncodeCNbrand(store.getCnbrand_store());
						storeMap.put(resultSet.getString(StoreTB.CNBRAND_STORE), resultSet.getInt("rowNum"));
						//storeMap.put(resultSet.getString(ReleaseTB.RELEASE_BRAND),resultSet.getInt("rowNum"));
					}
					
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return storeMap;
	}
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	public Map<String,List<StoreTB>> selectMap(){
		LinkedHashMap<String,List<StoreTB>> storeMap = new LinkedHashMap<String,List<StoreTB>> ();
		
		List<String> storeURLList = selectStoreURL();
		List<StoreTB> storeList = selectAllStore();
		
		
		
		for(String url : storeURLList){
			ArrayList<StoreTB> storeListForStore = new ArrayList<StoreTB>();
			
			for(StoreTB store : storeList){
				if(url.trim().equals(store.getUrl_store())){
					storeListForStore.add(store);
				}
			}
			
			storeMap.put(url, storeListForStore);
		}
		
		
		return storeMap;
	}
	
	/**
	 * @version 1.0
	 * @author GEE
	 */
	public Map<String,List<StoreTB>> selectMapByENBrand(String[] args){
		LinkedHashMap<String,List<StoreTB>> storeMap = new LinkedHashMap<String,List<StoreTB>> ();
		
		for(String str:args){
			storeMap.put(str, new ArrayList<StoreTB>()); 
		}
		
		String inStr = SqlMachine.toInStrs(args);
		
		String sql = "SELECT * FROM " + StoreTB.TABLE_NAME + " WHERE " + StoreTB.BRAND_STORE + " IN " + inStr;
		
		List<StoreTB> storeList = selectBySql(sql);
		
	
		for(StoreTB store : storeList){
			if(storeMap.get(store.getBrand_store())!=null){
				List<StoreTB> storeBrandList = storeMap.get(store.getBrand_store());
				storeBrandList.add(store);
				storeMap.put(store.getBrand_store(), storeBrandList);
			}
		}
			
		return storeMap;
	}
	
	public List<String> selectStoreURL(){
		ArrayList<String> storeURLList = new ArrayList<String>();
		
		String sql = "SELECT DISTINCT("+StoreTB.URL_STORE+") FROM "+StoreTB.TABLE_NAME;
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
				try {
					
					while(resultSet.next()){
						storeURLList.add(resultSet.getString(StoreTB.URL_STORE));
					}
					
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return storeURLList;
	}
	
	
	public void flow(int id){
		String sql = "update "+StoreTB.TABLE_NAME+" set " +StoreTB.FLOW_STORE + " = " + StoreTB.FLOW_STORE + "+1 where "+ StoreTB.ID_STORE + " = " +id;
		databaseConnection.executeUpdate(conn, sql);
	}
	
	
}
